#include "Scheduler.h"
#include <vector>
#include <iostream>

using namespace std;

Abstract_CPUScheduler::Abstract_CPUScheduler()
{
}

Abstract_CPUScheduler::~Abstract_CPUScheduler()
{
	processList.~vector();
}

/*
	This init function accepts a vector of pointers to Processesm and creates a copy
	of the processes into the private member function 'processList'
*/
void Abstract_CPUScheduler::init(vector<Process*> newList)
{	
	vector<Process*>::iterator create;

	for(create = newList.begin(); create != newList.end(); create++)
		processList.push_back(**create);

}


void Abstract_CPUScheduler::determineMeanWaitingTime()
{
    vector<Process>::iterator index;
    int sum = 0;
    
	for(index = processList.begin(); index != processList.end(); index++)
	{
		sum += ((*index).getEndTime() - (*index).getArrivalTIme() - (*index).getCPU_Burst());
	}

    meanWaitingTime = static_cast<double>(sum) / static_cast<double>(processList.size());
}

void Abstract_CPUScheduler::determineMeanTurnAroundTime()
{
    vector<Process>::iterator index;
    int sum = 0;
    
	for(index = processList.begin(); index != processList.end(); index++)
		sum += (*index).getEndTime() - (*index).getStartTime();

	meanTurnAroundTime = static_cast<double>(sum) / static_cast<double>(processList.size());
}

void Abstract_CPUScheduler::determineStats()
{
	determineMeanWaitingTime();
	determineMeanTurnAroundTime();
	determineMeanResponseTime();
}

double Abstract_CPUScheduler::getMeanWaitingTime()
{
	return meanWaitingTime;
}

double Abstract_CPUScheduler::getMeanTurnAroundTime()
{
	return meanTurnAroundTime;
}

double Abstract_CPUScheduler::getMeanResponseTime()
{
	return meanResponseTime;
}

void Abstract_CPUScheduler::determineMeanResponseTime() 
{
	vector<Process>::iterator index;
    int sum = 0;
    
	for(index = processList.begin(); index != processList.end(); index++)
		sum +=  (*index).getStartTime() - (*index).getArrivalTIme();

	meanTurnAroundTime = static_cast<double>(sum) / static_cast<double>(processList.size());

}